<?php

namespace app\controller\system;

use app\BaseController;
use think\response\Json;

class Rebate extends BaseController
{
    public function save(): Json
    {
        return $this->handle(function () {
            return $this->app->make(\app\model\StationRebate::class)->saveData();
        });
    }

    public function lst(): Json
    {
        return $this->handle(function () {
            return $this->app->make(\app\model\StationRebate::class)->pageData();
        });
    }

    public function detail(): Json
    {
        return $this->handle(function () {
            return $this->app->make(\app\model\StationRebate::class)->find($this->request->param("id"));
        });
    }

    public function search(): Json
    {
        return $this->handle(function () {
            return $this->app->make(\app\model\StationRebate::class)->where('state', 1)->column("*", "id");
        });
    }

    public function rule_save(): Json
    {
        return $this->handle(function () {
            return $this->app->make(\app\model\StationRebateRule::class)->saveData();
        });
    }

    public function rule_lst(): Json
    {
        return $this->handle(function () {
            return $this->app->make(\app\model\StationRebateRule::class)->pageData();
        });
    }

    public function rule_detail(): Json
    {
        return $this->handle(function () {
            $data = $this->app->make(\app\model\StationRebateRule::class)->find($this->request->param("id"));
            if (!empty($data)) {
                $data = $data->toArray();
                $data['pro_lst'] = json_decode($data['pro_lst'], true);
                $data['oil_type'] = json_decode($data['oil_type'], true);
            }
            return $data;
        });
    }
}
